$(function(){
    var view = function(){
        console.time('View_doc');
        if(this.hasAttribute('download')) return;
        $('.fCont').trigger('click');
        var layer = $("<div class='fCont'><style>\
.fCont {display: none; position: fixed; background: rgba(0,0,0,.5); width: 100%; height: 100%; margin: auto; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999}\
.fCont > div {display: none; height: 100%; width: 80%; position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: 15px auto; padding: 0 1px 0 0; z-index: 1000; background: #FFF}\
.frame-control-panel {display: none; position: absolute; background-color: rgba(147,147,147,0.7);}\
.frame-control-panel a {display: inline-block; width: 50px; height: 47px; line-height: 47px; text-align: center; font-size: 17px; font-weight: bold; text-decoration: none; color: rgba(255,255,255,.87); text-shadow: 0 1px 0 rgba(0,0,0,0.8);}\
.frame-control-panel a:hover {background: #838383; color: rgba(255,255,255,.87); cursor: default}\
.frame-control-panel a:nth-of-type(2) > div {background: url(https://ss.uooio.keenetic.pro:50005/static/uo-tashtagol.kemobl.ru/img/icons/doc_viewer/v-sprite19.svg) no-repeat 0 -2467px; background-origin: content-box; padding: 0px 0px 0 15px; margin-right: -15px;}\
</style>\
<div><div class='frame-control-panel'><a onclick="+"javascript:$('.fCont').trigger('click');"+">X</a><a href='"+$(this).attr('href')+"' download><div>&nbsp;</div></a></div>\
<iframe name='doc' src='' style='width:100%;height:100%;padding:0;margin:0'></iframe></div></div>"),
    //url = $(this).attr('href').substr(0,1) == '/'? document.location.origin + $(this).attr('href') : $(this).attr('href');
url = $(this)[0].href,
scroll = $(document.body).scrollTop();
        url = 'https://docs.google.com/viewerng/viewer?url='+ url +'&embedded=true';
        layer.find('iframe').attr('src',url);
        $(document.body).scrollTo(0, {duration:1000, onAfter:function(){$(this).css("overflow", "hidden");/*console.log(this);*/}});
        $(document.body).append(layer);
        $('.frame-control-panel').show().delay(9000).fadeOut(800);
        $('.fCont').find('iframe').on('load', ()=>console.log('frame loaded')).on('error', ()=>console.log('error')).hover(function(){$('.frame-control-panel').clearQueue().fadeIn(0);},function(event){
            if(!$(event.relatedTarget).parent().hasClass('frame-control-panel')) {$('.frame-control-panel').clearQueue().delay(1800).fadeOut(800);}});
        //Открываем\закрываем фрейм
        $('.fCont').fadeIn(1000, function(){$('.fCont').children('div').slideDown(1000);}).bind('click', function(){
            $(this).children('div').animate({marginTop:'100vh'}, 1500).parent().fadeOut(1500, function(){$(this).remove();$('html').css("overflow", "auto").scrollTo(scroll,{duration:1000});});
        });
        console.timeEnd('View_doc');
        return false;
    };

//добавляем свой селектор
jQuery.extend(jQuery.expr[':'], {
DV_fileType: function(el) {
let fileTypes = ['pdf', 'doc', 'docx', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'rtf'];
if(el.href && fileTypes.includes(el.href.toLowerCase().split('.').reverse()[0])) return true;
return false;
}
});

    $('body').addClass('doc-viewer').on('click', 'a:DV_fileType', view);
});